package socket;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class LoginServer {
    public static void main(String[] args) {
        int port = 6666;
        try(ServerSocket serverSocket = new ServerSocket(port)) {
            System.out.println("登录服务器已启动");
            while (true){
                Socket socket = serverSocket.accept();
                InputStream inputStream = socket.getInputStream();
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                String username = bufferedReader.readLine();
                OutputStream outputStream = socket.getOutputStream();
                PrintStream printStream = new PrintStream(outputStream);
                if (UserLogin.login(username)){
                    System.out.println(username+"登陆成功");
                    printStream.println("true");
                }else {
                    System.out.println(username+"登陆失败");
                    printStream.println("flase");
                }
                printStream.flush();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
